package alipay.openplatform.edu.campus.jiuye.common.utils;

/**
 * Created by zhz on 16/8/30.
 */
public class HideInfoHandleUtil {
   public enum InfoType{
        PHONE,CARDID,ADDR,EMAIL,BANKCARD
    }

    public static String hideHandle(InfoType type,String context){
        if (!org.apache.commons.lang3.StringUtils.isNotEmpty(context))
            return null;
        switch (type) {
            case PHONE:
                context = hidePhone(context);
                break;
            case CARDID:
                context = hideCardID(context);
                break;
            case EMAIL:
                context = hideEmail(context);
                break;
            case ADDR:
                // TODO: 16/8/30
                break;
            case BANKCARD:
                // TODO: 16/8/30
                break;
        }
        return context;
    }

    /**
     * 手机号:显示前3和后4位,其它用*代替。
     * @param phone
     * @return
     */
    public static String hidePhone(String phone){
        if (phone.length()>7) {
            StringBuilder sb = new StringBuilder(phone);
            phone = sb.replace(3,phone.length()-4,org.apache.commons.lang3.StringUtils.repeat("*",phone.length()-7)).toString();
        }
        return phone;
    }

    /**
     * 证件号码前台展示规范:前 1 位和后 1 位,其它用*号代替。
     * @param cardID
     * @return
     */
    public static String hideCardID(String cardID){
        if (cardID.length()>2) {
            StringBuilder sb = new StringBuilder(cardID);
            cardID = sb.replace(1,cardID.length()-1,org.apache.commons.lang3.StringUtils.repeat("*",cardID.length()-2)).toString();
        }
        return cardID;
    }

    /**
     * @前面的字符显示 3 位,3 位后显示 3 个 *,@后面完整显示如: con***@163.com
     * @param email
     * @return
     */
    public static String hideEmail(String email){
        // TODO: 16/8/31
        return null;
    }


    public static void main(String[] args) {
//        System.out.println(HideInfoHandleUtil.hidePhone("13511006179"));
//        System.out.println(org.apache.commons.lang3.StringUtils.repeat("*",10));
//          System.out.println(HideInfoHandleUtil.hideCardID("3708271992837435345"));
    }

}
